package cn.js.ccit.servlet;

import cn.js.ccit.service.UserService;
import cn.js.ccit.service.impl.UserServiceImpl;
import cn.js.ccit.vo.UserVo;
import com.mysql.cj.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取参数
        String userIdStr = req.getParameter("userId");
        List<UserVo> userList = new ArrayList<UserVo>();
        if(StringUtils.isNullOrEmpty(userIdStr)){
            //查询员工信息列表
            userList = userService.getAllUser();

        }else{
            //根据ID查询员工信息
            UserVo user = userService.getUserById(Integer.parseInt(userIdStr));
            userList.add(user);
        }
        req.setAttribute("userList", userList);
    }
}
